package models;

import boardGenerator.GameDifficultyLevel;
import boardGenerator.Solutions;
import boardGenerator.SudokuGenerator1;
import boardGenerator.SudokuGenerator2;

/**
 * Clase SudokuModelo
 * Implementa el modelo de juego sudoku
 * segun generador de tableros
 */
public class SudokuModelo {
    public static final int Model1 = 1;
    public static final int Model2 = 2;    
    private int[][] board;
    private int[][] solution;
    private int numberCount;
    
    /**
     * Contrusctor de la clase Segun modelo y dificultad
     * @param Model 1 or 2
     * @param diff 
     */
    public SudokuModelo(int Model,GameDifficultyLevel diff){
        if(Model==Model1){Model1(diff);}
        if(Model==Model2){Model2(diff);}        
    }
    
    /**
     * Modelo1: Crea tableros sudoku segun el generador 1
     * @param diff 
     */
    private void Model1(GameDifficultyLevel diff){
        SudokuGenerator1 uno = new SudokuGenerator1();        
        uno.generateProblemGrid(diff);        
        board = uno.getBoard();        
        Solutions.generateSolution(board);        
        solution = uno.getSolution();
        numberCount = uno.getNumberCount();
    }
    
    /**
     * Modelo2: Crea tableros sudoku segun generador 2
     * @param diff 
     */
    private void Model2(GameDifficultyLevel diff){
        SudokuGenerator2 dos = new SudokuGenerator2(diff);
        board = dos.getBoard();
        solution = dos.getSolution();
        numberCount = dos.getNumberCount();
    }
    
    /**
     * Obtiene el tablero generado (una copia)
     * @return 
     */
    public int[][] getBoard(){
        int[][] res = new int[9][9];
            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 9; j++) {
                    res[i][j] = board[i][j];
                }
            }
        return res;
    }
    
    /**
     * Obtiene el tablero Solucion (una copia)
     * @return 
     */
    public int[][] getSolution(){
        int[][] res = new int[9][9];
            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 9; j++) {
                    res[i][j] = solution[i][j];
                }
            }
        return res;
    }
    
    /**
     * Obtiene la cantidad de numeros en el tablero
     * @return 
     */
    public int getNumberCount(){
        return this.numberCount;
    }
}